#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from pathlib import Path


def main() -> None:
    prev_timestamp: int = 0
    for line in Path("omd_build_times.log").open():
        if not line.startswith("+++ ["):
            continue

        # line looks like this: +++ [1638200363] Build step '/home/lm/git/checkmk/omd/build/stamps/pre-install': done
        _sep, raw_timestamp, message = line.split(" ", 2)
        timestamp = int(raw_timestamp.strip("[]"))

        if not prev_timestamp:
            duration = "       -"
        else:
            duration = f"{timestamp - prev_timestamp:>5}sec"

        print(f"{duration} {message.rstrip()}")
        prev_timestamp = timestamp


if __name__ == "__main__":
    main()
